/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.alluringdecors.helper;

import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Administrator
 */
public class ValidateData {
   

    /**
     *Method to check Email
     *@param String n
     *@return boolean true or false
     */
    public boolean checkEmail(String n)
    {
        if(n.length()==0)
            return true;
        if (n==null)
        	return false;
        else
        {
            String strPattern = "\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b";
            Pattern p; Matcher m;
            int flag = Pattern.CASE_INSENSITIVE;
            p = Pattern.compile(strPattern,flag);
            m=p.matcher(n);
            return m.find();
        }
    }

    /**
     *Method to check Phone
     *@param String n
     *@return boolean true or false
     */
    public boolean checkPhone(String n)
    {
        if(n.equals(""))
            return true;
        if (n==null || n.length()>15 || n.length()<7)
        	return false;
        else
        {
            String strPattern = "[^0-9]";
            Pattern p;Matcher m;
            int flag = Pattern.CASE_INSENSITIVE;
            p = Pattern.compile(strPattern,flag);
            m = p.matcher(n);
            return !m.find();
        }
    }

    public boolean checkFloat(String n)
    {
        if (n==null||n.length()==0)
        	return false;
        else
        {
            try {
                float num=0.0f;
                num=Float.parseFloat(n);
                if(num>0)
                    return true;
                else
                    return false;
            } catch (NumberFormatException ex) {
                return false;
            }

        }
    }

    public boolean checkNull(String n)
    {
        if (n==null || n.length()==0)
        	return false;
        return true;
    }


    public boolean checkDateIn(String n)
    {
        if (n==null||n.length()<10)
        	return false;
        else
        {
            boolean flag=true;
            String dd,mm,yyyy;
            int d,m,y;
            yyyy=n.substring(0,4);
            mm=n.substring(5,7);
            dd=n.substring(8,10);
            try
            {
                    Date dat = new Date();
                    Calendar date = Calendar.getInstance();
                    date.setTime(dat);
                    int y1=date.get(Calendar.YEAR);
                    int m1=date.get(Calendar.MONTH);
                    int d1=date.get(Calendar.DAY_OF_MONTH);
	            m=Integer.parseInt(mm);
	            d=Integer.parseInt(dd);
	            y=Integer.parseInt(yyyy);
	            if ((d<1)&&(d>31))
	            	flag=false;
	            if ((m<1)&&(m>12))
	            	flag=false;
	            if (y<1)
	            	flag=false;
                    if(y1<y)
                        flag=false;
            }
            catch(Exception e)
            {
            	flag=false;
            }
            return flag;
        }
    }
    
}
